import pandas as pd


def rename_column_in_csv(input_file, output_file):
    try:
        # 读取CSV文件
        df = pd.read_csv(input_file)

        # 检查是否存在seller_id列
        if 'seller_id' in df.columns:
            # 重命名列
            df = df.rename(columns={'seller_id': 'merchant_id'})
            # 保存为新文件
            df.to_csv(output_file, index=False)
            print(f"成功将'seller_id'重命名为'merchant_id'并保存到{output_file}")
        else:
            print(f"错误：文件中不存在'seller_id'列")

    except FileNotFoundError:
        print(f"错误：找不到文件 {input_file}")
    except Exception as e:
        print(f"发生未知错误：{e}")


# 使用示例
if __name__ == "__main__":
    input_file = 'train_with_predictions.csv'  # 输入文件路径
    output_file = 'train_with_predictions_renamed.csv'  # 输出文件路径
    rename_column_in_csv(input_file, output_file)